package com.jprocms.module.cms.dal.mysql.sysword;

import com.jpro.framework.common.pojo.PageResult;
import com.jpro.framework.mybatis.core.mapper.BaseMapperX;
import com.jpro.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jprocms.module.cms.controller.admin.sysword.vo.SysWordExportReqVO;
import com.jprocms.module.cms.controller.admin.sysword.vo.SysWordPageReqVO;
import com.jprocms.module.cms.dal.dataobject.sysword.SysWordDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 词汇管理 Mapper
 *
 * @author jprocms
 */
@Mapper
public interface SysWordMapper extends BaseMapperX<SysWordDO> {

    default PageResult<SysWordDO> selectPage(SysWordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysWordDO>()
                .likeIfPresent(SysWordDO::getWord, reqVO.getWord())
                .eqIfPresent(SysWordDO::getDictType, reqVO.getDictType())
                .orderByAsc(SysWordDO::getSort));
    }

    default List<SysWordDO> selectList(SysWordExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<SysWordDO>()
                .likeIfPresent(SysWordDO::getWord, reqVO.getWord())
                .eqIfPresent(SysWordDO::getDictType, reqVO.getDictType())
                .orderByAsc(SysWordDO::getSort));
    }

    @Select("SELECT COUNT(*) FROM cms_sys_word WHERE update_time > #{maxUpdateTime}")
    Long selectCountByUpdateTimeGt(LocalDateTime maxTime);

}
